package com.etop.weibo.dao;

import com.etop.weibo.beans.StarAndFan;
import com.etop.weibo.beans.User;
import java.util.List;

import com.etop.weibo.util.WeiBoException;
import com.etop.weibo.util.HibernateUtil;
import java.util.HashMap;
import java.util.Map;
import org.hibernate.Session;

public class StarAndFanDao extends BaseDao<StarAndFan> {
    
    private final static String ID="id";
    private final static String STAR_ID="starId";
    private final static String FAN_ID="fanId";
    
    public void add(StarAndFan starAndFan) {
        super.add(starAndFan);
    }
        
    /**
     * @param starId
     * @param fanId 
     */
    public void delete(int starId, int fanId) {
        Map<String, Object> params = new HashMap<>();
        params.put("starId", starId);
        params.put("fanId", fanId);
//        super.deleteByHQL(StarAndFan.class, params);
    }

    public List<User> starsList(int fanId) {
        Session session = HibernateUtil.openSession();
        List<User> list = session.createQuery("from User user where user.id in "
                + "(select sf.starId from StarAndFan sf where sf.fanId=:fanId)")
                .setInteger("fanId", fanId)
                .list();
        session.close();
        return list;
    }

    public List<User> fansList(int starId) {
        Session session = HibernateUtil.openSession();
        List<User> list = session.createQuery("from User user where user.id in "
                + "(select sf.fanId from StarAndFan sf where sf.starId=:starId)")
                .setInteger("starId", starId)
                .list();
        session.close();
        return list;
    }
}